xenconsole: adjust pty opening error checking and handling
authorMatthew Daley <mattd@bugfuzz.com>
Sat, 14 Dec 2013 01:04:47 +0000 (14:04 +1300)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 16 Dec 2013 11:55:22 +0000 (11:55 +0000)
commit2d97f52713c3850bd3d6d865697a7738a98540aa
tree9a6bd375da1d68ed44cc0cee4ef287034d34a146
parent586ab6a055376ec3f3e1e82654eb87481005bc21
xenconsole: adjust pty opening error checking and handling

Currently we check the pty path received from xenstore with access(); if
it indicates that the pty is not accessible, we loop around and wait for
a new path to appear in xenstore.

This has several issues:
* If a path has been written to xenstore, it can be assumed that that
  pty should already be accessible to xenconsole, and hence any error
  that occurs while trying to open it should be fatal and not ignored
* If access() indicates no access to the pty, the memory allocated for
  the path is leaked when going around the loop again
* The accessibility of the pty could change between the access() and
  open() calls, leading to a TOCTOU race (this is what Coverity is
  complaining about).

By removing the explicit access() check and just erroring out whenever
open() fails, we fix all these issues.

Coverity-ID: 1056047
Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/console/client/main.c